<template>
    <!-- 法人公司列表组件 -->
    <div class="company-table-sec">
        <el-table class="table-list" style="width: 100%" :data="tableData"
                  :row-style="{height: '50px'}" :cell-style="{padding: '0'}"
                  :header-cell-style="{background:'#FAFBFC',color:'#999999'}"
                  border>
            <el-table-column align="center" type="index" label="序号" width="60"></el-table-column>
            <el-table-column align="center" prop="companyNo" label="法人公司编码"></el-table-column>
            <el-table-column align="center" prop="companyName" label="公司名称" width="200" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" prop="legalPerson" label="法人姓名"></el-table-column>
            <el-table-column align="center" prop="foundationDate" label="成立日期"></el-table-column>
            <el-table-column align="center" prop="registeredType" label="注册类型"></el-table-column>
            <el-table-column align="center" prop="employees" label="公司人数"></el-table-column>
            <el-table-column align="center" prop="registeredAddress" label="注册地址" width="220" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" prop="businessTerm" label="营业期限"></el-table-column>
            <el-table-column align="center" label="操作" width="100">
                <template slot-scope="scope">
                    <el-button class="edit-btn" @click="handleEdit(scope.$index)" type="text" size="small">编辑</el-button>
                    <el-divider direction="vertical"></el-divider>
                    <el-button :class="{'disable-btn': scope.row.status, 'enable-btn': !scope.row.status}" @click="changeStatus(scope.$index, scope.row.status)" type="text" size="small">{{scope.row.status ? '停用' : '启用'}}</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    // 引入法人公司模块接口
    import {getCompanyList} from "../../request/companyApi";

    export default {
        name: "companyTable",
        methods: {
            handleEdit(index) {
                console.log('点击编辑:', index);
                this.$store.commit('changeCompanyIndex', index);
                this.$router.push({name: 'companyEdit'});
            },
            // 启用/停用法人公司
            changeStatus(index, status) {this.$confirm(`此操作将${status ? '停用' : '启用'}该公司, 是否继续?`, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.tableData[index].status = !status;
                    this.$message({
                        type: 'success',
                        message: `${status ? '停用' : '启用'}成功!`
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });
                });
            },
        },
        data() {
            return {
                tableData: []
            }
        },
        mounted() {
            this.tableData = this.$store.state.companyTableData;
        }
    }
</script>

<style lang="less" scoped>
    /* 法人公司列表区域 */
    .company-table-sec {
        padding-top: 20px;
        overflow: auto;
        /* 列表 */
        .table-list {
            /* 操作按钮分割线 */
            .el-divider--vertical {
                margin: 0 5px;
            }
            /* 启用按钮 */
            .enable-btn {
                color: #42b983;
            }
            /* 停用按钮 */
            .disable-btn {
                color: #F56C6C;
            }
        }
    }
</style>
